package com.sinux.mms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinux.mms.entity.Record;
import com.sinux.mms.service.MemberServiceI;
import com.sinux.mms.service.RecordServiceI;

/**
 * 
 * @Description 消费记录控制层
 * @author w.g
 * @date 2017-6-16 17:24:02
 */
@Controller
@SuppressWarnings("all")
public class RecordController {
	@Autowired
	private MemberServiceI memberService;
	@Autowired
	private RecordServiceI recordService;
	
	/**
	 * 查询全部记录
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/recordtab")
	public Map<String, Object> recordTab(HttpServletRequest request, HttpServletResponse response, Model model){
		Map<String, Object> map=new HashMap<String, Object>();
		int offset =Integer.valueOf(request.getParameter("offset")); //当前页第一条数据(包含)  
	    int limit = Integer.valueOf(request.getParameter("limit")); //每页多少条数据  
		//页数=当前页第一条数据/每页多少条数据 +1
	    List<Record> records=recordService.findRecordPaging(offset/limit+1, limit);
		int total=recordService.findAllRecordList().size();
		map.put("rows", records);
		map.put("total", total);
		return map;
		
	}
	/**
	 * 根据路径跳转页面
	 * @return
	 */
	@RequestMapping("/testretab")
	public String test(){
		return "modules/record/recordTab";
	}
}
